<?php

class org extends Controller
{
	public function view( $name = NULL, $section = NULL, $action = NULL, $param = null, $param2 = null )
	{	
		$this->session();
		$orgs = new organization();
		$org = $orgs->getOrgByName( $name );
		$pm = new pm();
		$inboxUnread = $pm->countUnread( $_SESSION['stud_no'] );
		$adminModel = new admin();
		$memberModel = new member();
		$iAmAdmin = $adminModel->amIAdmin( $_SESSION['stud_no'], $org[0]['org_id'] );	
		$memberModel->updateLastVisit($_SESSION['stud_no'], $org[0]['org_id']);
		$iAmMember = $memberModel->amIMember( $_SESSION['stud_no'], $name );	
		$iAmBanned = $memberModel->amIBanned( $_SESSION['stud_no'], $org[0]['org_id'] );	
		if( $iAmBanned ) $iAmMember = false;
		if( $iAmAdmin ) $iAmMember = true;
		if( $_SESSION['admin'] == '1' ) $iAmMember = true;
		if( $_SESSION['admin'] == '1' ) $iAmAdmin = true;
		if( count( $org ) === 0 ) {
			$templateVars = array(
				'title' =>  'FEELS',
				'heading' => 'Sorry',
				'content' => 'The course with that name was not found.'
			);		
		}
		else {
			if( $section === NULL ) {
				$org = $orgs->getOrgByName( $name );
				$templateVars =  array(
					'title' =>  $org[0]['description'] .' - FEELS ',
					'heading' => $org[0]['description'],
					'content' => 
						'<h2 class="heading">Home</h2>'
						. '<div class="homepage">'
						. '<div class="summary">'. nl2br( $org[0]['long_description'] ) . '</div>'
						. '<div class="description" style="margin-bottom: 10px;">'
						. "<img class=\"orglogo\" src=\"/photos/$name.jpg\">"
						. nl2br( $org[0]['info'] ) . '</div>'
						. ( $iAmAdmin ? "<a href=\"/org/view/$name/edit-info\">Edit Info</a> " : '' )
						. ( $iAmAdmin ? "<a href=\"/org/view/$name/edit-logo\">Change Logo</a> " : '' )
						. '</div>',
					'highlight' => 'orginfo',
					'currentOrg' => $name
				);
			}
			elseif( $section === 'edit-info' ) {
				if( $action === NULL ) {
					$org = $orgs->getOrgByName( $name );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Edit Info - FEELS ',
						'heading' => $org[0]['description'],
						'content' => BufferedView::instance('org/forms/info', array(
							'action' => "/org/view/$name/edit-info/submit",
							'hiddenInputs' => array( 'org_id' => $org[0]['org_id'] ),
							'info' => $org[0]['info'],
							'orgname' => $name,
							'label' => 'Org information'
						) )->getBuffer(),
						'highlight' => 'orginfo',
						'currentOrg' => $name
					);
				}
				elseif( $action === 'submit' ) {
					$orgs->updateOrgInfo( $_POST['org_id'], $_POST['info'] );	
					header("Location: /org/view/$name");
				}
			}
			elseif( $section === 'edit-css' ) {
				if( $action === NULL ) {
					$org = $orgs->getOrgByName( $name );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Edit CSS - FEELS ',
						'heading' => $org[0]['description'],
						'content' => '<div><p>Click <a href="/editCss">here</a> for help in editing the CSS</p><p>All images that will be used in the CSS can be uploaded at the <a href="/org/view/'.$name.'/photos">Org Graphics</a> section.</p></div>'
						. BufferedView::instance('org/forms/info', array(
							'action' => "/org/view/$name/edit-css/submit",
							'hiddenInputs' => array( 'org_id' => $org[0]['org_id'] ),
							'info' => $org[0]['css'],
							'orgname' => $name,
							'label' => 'CSS'
						) )->getBuffer(),
						'highlight' => 'orginfo',
						'currentOrg' => $name
					);
				}
				elseif( $action === 'submit' ) {
					$orgs->updateCss( $_POST['org_id'], $_POST['info'] );	
					header("Location: /org/view/$name");
				}
			}
			elseif( $section === 'edit-logo' ) {
				if( $action === NULL || $action === 'invalid' ) {
					$org = $orgs->getOrgByName( $name );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Change Logo - FEELS ',
						'heading' => $org[0]['description'],
						'content' => (($action === 'invalid') ? 'File uploaded is not a valid image.' : '')
							. BufferedView::instance('org/forms/logo', array(
								'action' => "/org/view/$name/edit-logo/submit",
								'hiddenInputs' => array( 'org_id' => $org[0]['org_id'] ),
								'info' => $org[0]['css'],
								'orgname' => $name,
								'label' => 'Logo'
							) )->getBuffer(),
						'highlight' => 'orginfo',
						'currentOrg' => $name
					);
				}
				elseif( $action === 'submit' ) {
					try { 
						JF_ImageFile::instance( 
							JF_ImageData::fromFile( $_FILES['logo']['tmp_name'] )
							->resize(100,100)
						)->saveAsJPG("./photos/$name.jpg");
						header("Location: /org/view/$name");
					}
					catch ( JF_ImageDataException $e ) {
						if( $e->getCode() === JF_ImageDataException::INVALID_FORMAT ) header("Location: /org/view/$name/edit-logo/invalid");
					}
				}
			}
			elseif ( $section === 'announcements' ) {
				$articlesModel = new article();
				if( $action === NULL ) {
					$article = $articlesModel->getArticle( $name );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Announcements - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'organnouncements',
						'currentOrg' => $name,
						'content' => BufferedView::instance('org/announcements',
							array(
								'currentOrg' => $name,
								// 'name' => $org['name'],
								// 'description' => $org['description'],
								// 'long_description' => $org['long_description'],
								'announcements' => $article,
								// 'events' => $events,
								'isAdmin' => $iAmAdmin
							)
						)->getBuffer()
					);
				}
				else if( $action === 'show' ) {
					$article = $articlesModel->getArticleById( $param );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - View Announcement - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'organnouncements',
						'currentOrg' => $name,
						'content' => BufferedView::instance('org/announcement', 
								array(
									'currentOrg' => $name,
									'title' => $article['title'],
									'date' => $article['date'],
									'post' => $article['post'],
									'id' => $article['article_id'],
									'isAdmin' => $iAmAdmin
								)
							)->getBuffer()
					);
					if( $iAmMember ) {
						$commentModel = new commentArticle();
						$comments = $commentModel->getComment($article['article_id']);
						$templateVars['content'] .= BufferedView::instance('org/comments', 
								array(
									'comments'=>$comments,
									'isAdmin'=>$iAmAdmin,
									'orgname'=>$name,
									'section' => 'announcements'									
								)
						)->getBuffer();
						$templateVars['content'] .= BufferedView::instance('org/forms/comment', 
								array(
									'action' => "/org/view/$name/announcements/comment",
										'hiddenInputs' => array(
										'article_id' => $param
									)
								)
						)->getBuffer();
					}
					if( $param2 === 'blankcomment' ) {
						$templateVars['content'] .= 'Do not leave the comment field blank';
					}
				}
				else if( $action === 'comment' ) {
					if( !empty( $_POST['post'] ) ) {
						$commentModel = new commentArticle();
						$commentModel->insertComment ( $_POST['article_id'], $_SESSION['stud_no'], gmdate('Y-m-d H:i:s'), $_POST['post'] );
						header("Location: /org/view/$name/announcements/show/" . $_POST['article_id'] 	);
					}
					else {
						header("Location: /org/view/$name/announcements/show/" . $_POST['article_id'] . "/blankcomment" );
					}
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Comment - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'organnouncements',
						'currentOrg' => $name,
						'content' => 'Comment posted. Click here'
					);
				}
				else if( $action === 'comment-delete' ) {
					$commentModel = new commentArticle();
					$commentModel->deleteComment( $param );
					header('Location: ' . $_SERVER['HTTP_REFERER'] );
					//header("Location: /org/view/$name/announcements/show/" . $_POST['article_id']);
				}				
				else if( $action === 'add' ) {
					$orgModel = new organization();
					$orgId = $orgModel->getOrgId( $name );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Add Announcement - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'organnouncements',
						'currentOrg' => $name,
						'content' => BufferedView::instance('org/forms/announcement', 
							array(
								'action'=>"/org/view/$name/announcements/add-confirm",
								'hiddenInputs'=>array('org_id'=>$orgId)
							) 
						)->getBuffer()						
					);
				}
				else if( $action === 'add-confirm' ) {
					if( !empty($_POST['title']) && !empty($_POST['post'] ) ) {
						try {
							$articlesModel->insertArticle( 
								$_POST['org_id'], 
								$_POST['title'], 
								$_POST['post'],
								gmdate('Y-n-d H:i:s')
							);
							//$transport = Swift_SmtpTransport::newInstance();
							//$transport = Swift_SmtpTransport::newInstance('localhost', 25);
							$transport = Swift_SmtpTransport::newInstance('mail.steadfast.net', 25);
							$mailer = Swift_Mailer::newInstance($transport);
							$mailinglist = $memberModel->getMailAddresses($org[0]['org_id']);
							$message = Swift_Message::newInstance('An announcement has been posted to FEELS')
							  ->setFrom(array('admin@sooc.dijiyd.com' => 'FEELS'))
							  ->setBcc($mailinglist)
							  ->setBody("Hello,
You're receiving this message because an announcement has been posted to {$org[0]['description']} at FEELS:
									
{$_POST['title']}
									
{$_POST['post']}
							  
Please visit {$org[0]['description']} at FEELS.")	
							  ;
							
							$result = $mailer->send($message);							
							$templateVars =  array(
								'title' =>  $org[0]['description'] .' - Add Announcement - FEELS ',
								'heading' => $org[0]['description'],
								'highlight' => 'organnouncements',
								'currentOrg' => $name,
								'content' => 'Announcement has been posted and mailed to '. $result .' members. Click <a href="/org/view/' . $name . '/announcements">here</a> to go back to announcements.'
							);
						} 
						catch( Exception $e ) {
							$templateVars =  array(
								'title' =>  $org[0]['description'] .' - Add Announcement - FEELS ',
								'heading' => $org[0]['description'],
								'highlight' => 'organnouncements',
								'currentOrg' => $name,
								'content' => 'There has been an error. ' . 	$e->getMessage()
							);
						}
					}
					else {
						$templateVars =  array(
							'title' =>  $org[0]['description'] .' - Add Announcement - FEELS ',
							'heading' => $org[0]['description'],
							'highlight' => 'organnouncements',
							'currentOrg' => $name,
							'content' => '<p>Please fill in all fields.</p>'
								. BufferedView::instance('org/forms/announcement', 
								array(
									'action'=>"/org/view/$name/announcements/add-confirm",
									'title'=> $article['title'],
									'post'=> $article['post'],
									'hiddenInputs'=>array('org_id'=>$orgId)
								) 
							)->getBuffer()
						);
					}
				}
				else if( $action === 'edit' ) {
					$article = $articlesModel->getArticleById( $param );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Edit Announcement - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'organnouncements',
						'currentOrg' => $name,
						'content' => BufferedView::instance('org/forms/announcement', 
							array(
								'action'=>"/org/view/$name/announcements/edit-confirm",
								'title'=> $article['title'],
								'post'=> $article['post'],
								'hiddenInputs'=>array('article_id'=>$param)
							) 
						)->getBuffer()
					);
				}
				else if( $action === 'edit-confirm' ) {
					if( !empty($_POST['title']) && !empty($_POST['post'] ) ) {
						try {
							$articlesModel->updateArticle( 
								$_POST['article_id'], 
								$_POST['title'], 
								$_POST['post'],
								gmdate('Y-n-d H:i:s')
							);
							$templateVars =  array(
								'title' =>  $org[0]['description'] .' - Edit Announcement - FEELS ',
								'heading' => $org[0]['description'],
								'highlight' => 'organnouncements',
								'currentOrg' => $name,
								'content' => 'Announcement has been updated. Click <a href="/org/view/' . $name . '/announcements">here</a> to go back to announcements.'
							);
						} 
						catch( Exception $e ) {
							$templateVars =  array(
								'title' =>  $org[0]['description'] .' - Edit Announcement - FEELS ',
								'heading' => $org[0]['description'],
								'highlight' => 'organnouncements',
								'currentOrg' => $name,
								'content' => 'There has been an error. ' . 	$e->getMessage()
							);
						}
					}
					else {
						$templateVars =  array(
							'title' =>  $org[0]['description'] .' - Edit Announcement - FEELS ',
							'heading' => $org[0]['description'],
							'highlight' => 'organnouncements',
							'currentOrg' => $name,
							'content' => '<p>Please fill in all fields</p>'
							. BufferedView::instance('org/forms/announcement', 
								array(
									'action'=>"/org/view/$name/announcements/edit-confirm",
									'title'=> $_POST['title'],
									'post'=> $_POST['post'],
									'hiddenInputs'=>array('article_id'=>$_POST['article_id'])
								) 
							)->getBuffer()
						);
					}
				}
				else if( $action === 'delete' ) {
					$article = $articlesModel->getArticleById( $param );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Delete Announcement - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'organnouncements',
						'currentOrg' => $name,
						'content' => 'Are you sure you wish to delete the following announcement?' 
							. BufferedView::instance('org/announcement', 
								array(
									'name' => $org['name'],
									'description' => $org['description'],
									'long_description' => $org['long_description'],
									'title' => $article['title'],
									'date' => $article['date'],
									'post' => $article['post'],
								)
							)->getBuffer()
							. BufferedView::instance('org/forms/confirm', 
								array(
									'action' => "/org/view/$name/announcements/delete-confirm",
									'hiddenInputs' => array(
										'article_id' => $param
									)
								)
							)->getBuffer()
					);
				}
				else if( $action === 'delete-confirm' ) {
					try {
						if( $_POST['confirm-yes'] ) {
							$articlesModel->deleteArticle( $_POST['article_id'] );
							$templateVars =  array(
								'title' =>  $org[0]['description'] .' - Delete Announcement - FEELS ',
								'heading' => $org[0]['description'],
								'highlight' => 'organnouncements',
								'currentOrg' => $name,
								'content' => 'Announcement has been removed. Click <a href="/org/view/' . $name . '/announcements">here</a> to go back to announcements.'
							);
						}
						else {
							header("Location: /org/view/$name/announcements");
						}
					} catch( Exception $e ) {
						$templateVars =  array(
							'title' =>  $org[0]['description'] .' - Delete Announcement - FEELS ',
							'heading' => $org[0]['description'],
							'highlight' => 'organnouncements',
							'currentOrg' => $name,
							'content' => 'There has been an error. ' . 	$e->getMessage()
						);
					}
				}
			}
			elseif( $section === 'events' ) {
				$eventsModel = new event();
				if( $action === NULL ) {
					$events = $eventsModel->getEvent( $name );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Announcements - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'organnouncements',
						'currentOrg' => $name,
						'content' => BufferedView::instance('org/events',
							array(
								'currentOrg' => $name,
								// 'name' => $org['name'],
								// 'description' => $org['description'],
								// 'long_description' => $org['long_description'],
								// 'announcements' => $article,
								'events' => $events,
								'isAdmin' => $iAmAdmin
							)
						)->getBuffer()
					);
				}
				else if( $action === 'show' ) {
					$event = $eventsModel->getEventById( $param );
					$regModel = new registration();					
					$event = $event[0];
					$event['isAdmin'] = $iAmAdmin;
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - View Event - FEELS ',
						'heading' => $org[0]['description'],
						'currentOrg' => $name,
						'content' => BufferedView::instance('org/event', 
								array_merge( $event, array('currentOrg' =>$name))
							)->getBuffer()

					);
					if( $iAmMember ) {
						$templateVars['content'] .= BufferedView::instance('org/event_registered', 
								array(
									'registereds' => $regModel->getRegList( $event['event_id'] )
								)
						)->getBuffer();
						if( (strtotime($event['date'] ) - (6*60*60*24)) > gmmktime() ) {
							if( !$regModel->isRegistered( $_SESSION['stud_no'], $event['event_id'] ) ) {
								$templateVars['content'] .= BufferedView::instance('org/forms/register', 
										array(
											'action'=> "/org/view/$name/events/register",
											'event_id'=> $event['event_id'],
											'org_id'=>$org[0]['org_id']
										)
								)->getBuffer();
							} else {
								$templateVars['content'] .= 'You have registered for this activity.';
							}
						} 
						else {
							$templateVars['content'] .= 'Registration period has ended.';
						}
						$commentModel = new commentEvent();
						$comments = $commentModel->getComment($event['event_id']);
						$templateVars['content'] .= BufferedView::instance('org/comments', 
								array(
									'comments'=>$comments,
									'isAdmin'=>$iAmAdmin,
									'orgname'=>$name,
									'section' => 'events'									
								)
						)->getBuffer();
						$templateVars['content'] .= BufferedView::instance('org/forms/comment', 
								array(
									'action' => "/org/view/$name/events/comment",
									'hiddenInputs' => array(
										'event_id' => $param
									)
								)
							)->getBuffer();
						if( $param2 === 'blankcomment' ) {
							$templateVars['content'] .= 'Do not leave the comment field blank';
						}
					}
				}
				else if( $action === 'comment' ) {
					if( !empty( $_POST['post'] ) ) {
						$commentModel = new commentEvent();
						$commentModel->insertComment ( $_POST['event_id'], $_SESSION['stud_no'], gmdate('Y-m-d H:i:s'), $_POST['post'] );
						header("Location: /org/view/$name/events/show/" . $_POST['event_id'] );
					}
					else {
						header("Location: /org/view/$name/events/show/" . $_POST['event_id'] . "/blankcomment" );
					}
					
				}
				elseif( $action === 'comment-delete' ) {
					$commentModel = new commentEvent();
					$commentModel->deleteComment( $param );
					header("Location: " . $_SERVER['HTTP_REFERER'] );
					//header("Location: /org/view/$name/events/show/" . $_POST['article_id']);
				}
				else if( $action === 'register' ) {
					$model = new registration();
					$register = $model->insertReg( $_POST['eventId'], $_POST['orgId'],$_SESSION['stud_no'] ); 
					$message = "You have been registered for this event.
					Click <a href=\"/org/view/$name/events/show/{$_POST['eventId']}\">here</a> to go back." ;
					$templateVars['content'] = $message;
				}
				else if( $action === 'add' ) {
					$orgModel = new organization();
					$orgId = $orgModel->getOrgId( $name );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Add Event - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'orgevents',
						'currentOrg' => $name,
						'content' => 
							($param === 'invalid' ? 'Please fill in all fields' : '' )
							. BufferedView::instance('org/forms/event', 
							array(
								'action'=>"/org/view/$name/events/add-confirm",
								'hiddenInputs'=>array('org_id'=>$orgId)
							) 
						)->getBuffer()						
					);
				}
				else if( $action === 'add-confirm' ) {
					if( 	!empty($_POST['org_id']) &&
							!empty($_POST['name']) &&
							!empty($_POST['date']) &&
							!empty($_POST['fee']) &&
							!empty($_POST['venue']) &&
							!empty($_POST['description'])	) {
						try {
							$eventsModel->insertEvent( 
								$_POST['org_id'], 
								$_POST['name'], 
								$_POST['date'], 
								$_POST['starthour']. ':' .$_POST['startminute'], 
								$_POST['endhour']. ':' .$_POST['endminute'], 
								$_POST['fee'], 
								$_POST['venue'], 
								$_POST['description']
							);
							$templateVars =  array(
								'title' =>  $org[0]['description'] .' - Add Event - FEELS ',
								'heading' => $org[0]['description'],
								'currentOrg' => $name,
								'content' => 'Event has been posted. Click <a href="/org/view/' . $name . '/events">here</a> to go back to events.'
							);

						} catch( Exception $e ) {
							$templateVars =  array(
								'title' =>  $org[0]['description'] .' - Add Event - FEELS ',
								'heading' => $org[0]['description'],
								'currentOrg' => $name,
								'content' => 'There has been an error. ' . 	$e->getMessage()
							);
						}
					}
					else {
						header("Location: /org/view/$name/events/add/invalid");
					}
				}
				else if( $action === 'edit' ) {
					$event = $eventsModel->getEventById( $param );
					$event = $event[0];
					$stime = explode( ':', $event[0]['starttime'] );
					$etime = explode( ':', $event[0]['endtime'] );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Edit Event - FEELS ',
						'heading' => $org[0]['description'],
						'currentOrg' => $name,
						'content' => BufferedView::instance('org/forms/event', 
							array(
								'action'=>"/org/view/$name/events/edit-confirm",
								'name'=> $event['Event'],
								'description'=> $event['description'],
								'date'=> $event['date'],
								'starthour'=> $stime[0],
								'startminute'=> $stime[1],
								'endhour'=> $etime[0],
								'endminute'=> $etime[1],
								'fee'=> $event['fee'],
								'venue'=> $event['venue'],
								'hiddenInputs'=>array('event_id'=>$param)
							) 
						)->getBuffer()
					);
				}
				else if( $action === 'edit-confirm' ) {
					try {
						$eventsModel->updateEvent( 
							$_POST['event_id'], 
							$_POST['name'], 
							$_POST['date'],
							$_POST['starthour'] .':'. $_POST['startminute'],
							$_POST['endhour'] .':'. $_POST['endminute'],
							$_POST['fee'],
							$_POST['venue'],
							$_POST['description']
						);
						$templateVars =  array(
							'title' =>  $org[0]['description'] .' - Edit Event - FEELS ',
							'heading' => $org[0]['description'],
							'currentOrg' => $name,
							'content' => 'Event has been updated. Click <a href="/org/view/' . $name . '/events">here</a> to go back to Events.'
						);
					} 
					catch( Exception $e ) {
						$templateVars =  array(
							'title' =>  $org[0]['description'] .' - Edit Event - FEELS ',
							'heading' => $org[0]['description'],
							'currentOrg' => $name,
							'content' => 'There has been an error. ' . 	$e->getMessage()
						);
					}
				}
				else if( $action === 'delete' ) {
					$event = $eventsModel->getEventById( $param );
					$event = $event[0];
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Delete Event - FEELS ',
						'heading' => $org[0]['description'],
						'currentOrg' => $name,
						'content' => 'Are you sure you wish to delete the following event?' 
							. BufferedView::instance('org/event', 
								$event
							)->getBuffer()
							. BufferedView::instance('org/forms/confirm', 
								array(
									'action' => "/org/view/$name/events/delete-confirm",
									'hiddenInputs' => array(
										'event_id' => $param
									)
								)
							)->getBuffer()
					);
				}
				else if( $action === 'delete-confirm' ) {
					try {
						if( $_POST['confirm-yes'] ) {
							$eventsModel->deleteEvent( $_POST['event_id'] );
							$templateVars =  array(
								'title' =>  $org[0]['description'] .' - Delete Event - FEELS ',
								'heading' => $org[0]['description'],
								'currentOrg' => $name,
								'content' => 'Event has been removed. Click <a href="/org/view/' . $name . '/events">here</a> to go back to events.'
							);
						}
						else {
							header("Location: /org/view/$name/events");
						}
					} catch( Exception $e ) {
						$templateVars =  array(
							'title' =>  $org[0]['description'] .' - Delete Announcement - FEELS ',
							'heading' => $org[0]['description'],
							'highlight' => 'organnouncements',
							'currentOrg' => $name,
							'content' => 'There has been an error. ' . 	$e->getMessage()
						);
					}
				}
				$templateVars['highlight'] = 'orgevents';	
			}
			elseif( $section === 'tutorials' ) {
				$tutorialsModel = new tutorial();
				if( $action === NULL ) {
					$tutorials = $tutorialsModel->getTutorial( $name );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Tutorials - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'orgtutorial',
						'currentOrg' => $name,
						'content' => BufferedView::instance('org/tutorials',
							array(
								// 'name' => $org['name'],
								// 'description' => $org['description'],
								// 'long_description' => $org['long_description'],
								'tutorials' => $tutorials,
								'orgname' => $name,
								'isAdmin' => $iAmAdmin
								)
						)->getBuffer()
					);
				}
				elseif( $action === 'show' ) {
					$tutorial = $tutorialsModel->getTutorialById( $param );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Tutorials - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'orgtutorial',
						'currentOrg' => $name,
						'content' => BufferedView::instance('org/tutorial',
							array(
								'name' => $org['name'],
								'description' => $org['description'],
								'long_description' => $org['long_description'],
								'announcements' => $article,
								'tutorial' => $tutorial[0],
								'orgid' => $org[0]['org_id'],
								'orgname' => $name,
								'isAdmin' => $iAmAdmin
							)
						)->getBuffer()
					);
					if( $iAmMember ) {
						$commentModel = new commentTutorial();
						$comments = $commentModel->getComment($tutorial[0]['topic_id']);
						$templateVars['content'] .= BufferedView::instance('org/comments', 
								array(
									'comments'=>$comments,
									'isAdmin'=>$iAmAdmin,
									'orgname'=>$name,
									'section' => 'tutorials'																		
								)
						)->getBuffer();
						$templateVars['content'] .= BufferedView::instance('org/forms/comment', 
								array(
									'action' => "/org/view/$name/tutorials/comment",
									'hiddenInputs' => array(
										'topic_id' => $param
									)
								)
						)->getBuffer();
					}
					if( $param2 === 'blankcomment' ) {
						$templateVars['content'] .= 'Do not leave the comment field blank';
					}
				}
				else if( $action === 'comment' ) {
					if( !empty( $_POST['post'] ) ) {
						$commentModel = new commentTutorial();
						$commentModel->insertComment ( $_POST['topic_id'], $_SESSION['stud_no'], gmdate('Y-m-d H:i:s'), $_POST['post'] );
						header("Location: /org/view/$name/tutorials/show/" . $_POST['topic_id'] 	);
					}
					else {
						header("Location: /org/view/$name/tutorials/show/" . $_POST['topic_id'] .'/blankcomment' );
					}
				}
				elseif( $action === 'comment-delete' ) {
					$commentModel = new commentTutorial();
					$commentModel->deleteComment( $param );
					header("Location: " . $_SERVER['HTTP_REFERER'] );
					//header("Location: /org/view/$name/announcements/show/" . $_POST['article_id']);
				}
				elseif( $action === 'add' ) {
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Comment - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'orgtutorial',
						'currentOrg' => $name,
						'content' => 
							( $param === 'invalid' ? 'Please fill in all fields' : '' )
							. ( $param === 'fail' ? 'Could not upload' : '' )
							. BufferedView::instance('org/forms/tutorial', array(
							'action' => "/org/view/$name/tutorials/add-confirm"
						) )->getBuffer()
					);
				}
				elseif( $action === 'add-confirm' ) {
					if( !empty( $_POST['title'] ) && !empty( $_POST['description'] ) ) {
						$tutorialModel = new tutorial();
						$tutorialId = $tutorialModel->insertTutorial( $org[0]['org_id'], $_FILES['file']['name'], $_POST['title'], gmdate('Y-m-d H:i:s'), $_POST['description'] );
						if( end( explode('.', strtolower( $_FILES['file']['name'] ) ) ) === 'pdf' ) {
							if( !file_exists("./pdfs/{$org[0]['org_id']}") ) mkdir( "./pdfs/{$org[0]['org_id']}" );
							if( move_uploaded_file( $_FILES['file']['tmp_name'], "./pdfs/{$org[0]['org_id']}/$tutorialId.pdf" ) ) $uploadComplete = $tutorialModel->insertTutorialDone();
							else $uploadComplete = $tutorialModel->insertTutorialFail();
						}
						else {
							$uploadComplete = $tutorialModel->insertTutorialFail();
						}
						$templateVars =  array(
							'title' =>  $org[0]['description'] .' - Comment - FEELS ',
							'heading' => $org[0]['description'],
							'highlight' => 'orgtutorials',
							'currentOrg' => $name
						);
						if( $uploadComplete ) header("Location: /org/view/$name/tutorials/");
						else header("Location: /org/view/$name/tutorials/add/fail");
					}
					else header("Location: /org/view/$name/tutorials/add/invalid");
				}
				elseif( $action === 'edit' ) {
				
				}
				elseif( $action === 'edit-confirm' ) {
				
				}
				elseif( $action === 'delete' ) {
					$tutorial = $tutorialsModel->getTutorialById( $param );
					$templateVars =  array(
						'title' =>  $org[0]['description'] .' - Tutorial - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'orgtutorials',
						'currentOrg' => $name,
						'content' => "Are you sure you wish to delete this tutorial?"
						. BufferedView::instance('org/tutorial',
							array(
								'name' => $org['name'],
								'description' => $org['description'],
								'long_description' => $org['long_description'],
								'announcements' => $article,
								'tutorial' => $tutorial[0],
								'orgid' => $org[0]['org_id'],
								'orgname' => $name
							)
						)->getBuffer()
						. BufferedView::instance('org/forms/confirm', array(
							'action' => "/org/view/$name/tutorials/delete-confirm",
							'hiddenInputs' => array( 'topic_id' => $param, 'org_id'=>$org[0]['org_id'] )
						) )->getBuffer()
					);
				}
				elseif( $action === 'delete-confirm' ) {
					if( isset($_POST['confirm-yes'] ) ) {
						$file = "./pdfs/{$org[0]['org_id']}/{$_POST['topic_id']}.pdf";
						if( file_exists( $file ) ) unlink( $file ) ;
						$tutorialsModel->deleteTutorial( $_POST['topic_id'] );
						header("Location: /org/view/$name/tutorials/");
						
					}
					else header("Location: /org/view/$name/tutorials/");
				}
			}
			elseif( $section === 'memberlist' ) {
				$membersModel = new member();
				$members = $membersModel->getOrgMembersAdminByOrgName( $name );
				$templateVars =  array(
					'title' =>  $org[0]['description'] .' - Members - FEELS ',
					'heading' => $org[0]['description'],
					'highlight' => 'orgmember',
					'currentOrg' => $name,
				);
				$templateVars['content'] = '';
				if( $iAmAdmin ) {
					if( isset( $action ) && $action === 'add' ) {
						$already = $membersModel->isMember( $param, $org[0]['org_id'] );
						if( !$already ) {
							$membersModel->insertMember( $param, $org[0]['org_id'], gmdate('Y-m-d H:i:s'), 0 );
							$usermodel = new user();
							$pmmodel = new pm();
							$user = $usermodel->findUser($param);
							$mi = $user[0]['middlename']{0};
							$username = ucwords( strtolower( "{$user[0]['lastname']}, {$user[0]['firstname']} $mi." ));
							$subject = 'Notification of new membership';
							$message = "Student number: {$param}
	Attention, $username:
	You are now a member of {$org[0]['description']}.";
							$pmmodel->insertPm( $_SESSION['stud_no'], $param, gmdate('Y-m-d H:i:s'), $subject, $message );						
							header("Location: /org/view/$name/memberlist");
						}
						
					}
					elseif( isset( $action ) && $action === 'remove' ) {
						if( $membersModel->isMember( $param, $org[0]['org_id'] ) ) $membersModel->deleteMember( $param, $org[0]['org_id'] );
						header("Location: /org/view/$name/memberlist");
					}
					elseif( isset( $action ) && $action === 'ban' ) {
						if( $membersModel->isMember( $param, $org[0]['org_id'] ) ) $membersModel->ban( $param, $org[0]['org_id'] );
						header("Location: /org/view/$name/memberlist");
					}
					elseif( isset( $action ) && $action === 'unban' ) {
						if( $membersModel->isMember( $param, $org[0]['org_id'] ) ) $membersModel->unban( $param, $org[0]['org_id'] );
						header("Location: /org/view/$name/memberlist");
					}
					if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
						$userModel = new user();
						$result = $userModel->findUser( $_POST['search'] );
						if( count( $result ) > 0  ) {
							$result = $result[0];
							$nohits = NULL;

						}
						else { 
							$result = NULL;
							$result = NULL;
							$nohits = $_POST['search'];
						}
					}
					$templateVars['content'] .= BufferedView::instance('org/forms/find_member', array(
						'name' => $name,
						'result' => $result,
						'already' => $already,	
						'nohits' => $nohits
					) )->getBuffer();
				}
				
				$templateVars['content'] .= BufferedView::instance('org/memberlist',
					array(
						'name' => $name	,
						// 'description' => $org['description'],
						// 'long_description' => $org['long_description'],
						'members' => $members,
						'orgAdmin' => $iAmAdmin
					)
				)->getBuffer();
			}
			elseif( $section === 'ban' ) {
				$templateVars['currentOrg'] = $name;
				$templateVars['content'] .= BufferedView::instance('org/forms/banning',
					array(
						'action'=> "/org/view/$name/ban-confirm",
						'hiddenInputs' => array(
							'stud_no' => $action
						)
					)
				)->getBuffer();
			}
			elseif( $section === 'ban-confirm' ) {
				if( $_POST['confirm-yes'] && !empty( $_POST['reason'] ) ) {
					$membermodel = new member();
					$membermodel->ban( $_POST['stud_no'], $org[0]['org_id'] );
					$usermodel = new user();
					$user = $usermodel->findUser($_POST['stud_no']);
					$admins = $usermodel->getSiteAdmin();
					$model = new pm();
					$bannedmi = $user[0]['middlename']{0};
					$banneduser = ucwords( strtolower( "{$user[0]['lastname']}, {$user[0]['firstname']} $bannedmi." ));
					$reason = $_POST['reason'];
					$subject = 'Notification for banning';
					$message = "Student number: {$_POST['stud_no']}
	$banneduser is being banned for reason:
				
	$reason
					";
					$model->insertPm( $_SESSION['stud_no'], $_POST['stud_no'], gmdate('Y-m-d H:i:s'), $subject, $message );
					foreach( $admins as $admin) {
						$model->insertPm( $_SESSION['stud_no'], $admin['stud_no'], gmdate('Y-m-d H:i:s'), $subject, $message );
					}
				}
				elseif( $_POST['confirm-no'] ) {
				
				}
				header("Location: /org/view/$name/memberlist");
			}
			elseif( $section === 'forum' ) {
				$model = new forum();
				$orgForums = $model->getForums($name);
				if( $action === NULL )
				{
					$templateVars =  array(
						'title' => 'Forums - FEELS',
						'heading' => $org[0]['description'],
						'highlight' => 'orgforum',
						'currentOrg' => $name,
						'content' => BufferedView::instance('org/forums',array(
							"forums" => $orgForums,
							'orgname' => $name,
							'isAdmin' => $iAmAdmin,
						) )->getBuffer()
					);
				}
				if( $action === 'view' )
				{
					$threads = $model->getThreads($param);
					
					$templateVars =  array(
						'title' =>  'Forums - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'orgforum',
						'currentOrg' => $name,
						'content' => BufferedView::instance('org/threads',array(
							"threads" => $threads,
							'orgname' => $name,
							'forumid' => $param,
							'isAdmin' => $iAmAdmin,
							'isMember' => $iAmMember
						) )->getBuffer()
					);							
				}
				elseif( $action === 'new' ) {
					$templateVars =  array(
						'title' =>  'Forums - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'orgforum',
						'currentOrg' => $name,
						'content' => 
							( $param === 'invalid' ? 'Please fill in all fields' : '' )
							. BufferedView::instance('org/forms/forum',array(
							"action" => "/org/view/$name/forum/new-confirm"
						) )->getBuffer()
					);				
				}
				elseif( $action === 'new-confirm' ) {
					if( !empty( $_POST['name'] ) ) {
						$forum = $model->insertForum( $org[0]['org_id'], $_POST['name'], $_POST['description'], gmdate('Y-m-d H:i:s'), 0, NULL );
						header("Location: /org/view/$name/forum");
					}
					else {
						header("Location: /org/view/$name/forum/new/invalid");
					}
				}
				elseif( $action === 'edit' ) {
					$forum = $model->getForum($param);
					$templateVars =  array(
						'title' =>  'Forums - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'orgforum',
						'currentOrg' => $name,
						'content' => BufferedView::instance('org/forms/forum',array(
							"action" => "/org/view/$name/forum/edit-confirm/$param",
							"name" => $forum['title'],
							"description" => $forum['description']
						) )->getBuffer()
					);				
				}
				elseif( $action === 'edit-confirm' ) {
					if( !empty( $_POST['name'] ) ) $forum = $model->updateForum($_POST['name'], $_POST['description'], $param);
					header("Location: /org/view/$name/forum");
				}
				elseif( $action === 'delete' ) {
					$forum = $model->getForum($param);
					$templateVars =  array(
						'title' =>  'Forums - FEELS ',
						'heading' => $org[0]['description'],
						'highlight' => 'orgforum',
						'currentOrg' => $name,
						'content' => 'Are you sure you wish to delete this forum?'
							. BufferedView::instance('org/forum', array(
								'row' => $forum,
							))->getBuffer()
							. BufferedView::instance('public/forms/confirm', array(
								'action' => "/org/view/$name/forum/delete-confirm/$param",
								'hiddenInputs' => array()
							))->getBuffer()
					);		
					$output .= BufferedView::instance('org/forum', array(
						'row' => $forum,
					))->getBuffer();
					$output .= BufferedView::instance('public/forms/confirm', array(
						'action' => "/org/view/$name/forum/delete-confirm/$param",
						'hiddenInputs' => array()
					))->getBuffer();
				}
				elseif( $action === 'delete-confirm' ) {
					if( $_POST['confirm-yes'] ) {
						$model->deleteForum($param);
						header("Location: /org/view/$name/forum");
					}
					elseif( $_POST['confirm-no'] ) {
						$forum = $model->lookupThreadForum($param);
						header("Location: /org/view/$name/forum");
					}
				}

			}
			elseif( $section === 'thread' ) { 
				$this->session();
				$model = new forum();
				if( $action === 'view' ) {
					$post = $model->getPosts($param);
					$forum = $model->lookupThreadForum($param);
					$model->updateThreadViews($param);
					$output = BufferedView::instance('org/posts',array(
						"posts" => $post,
						'orgname' => $name,
						'forum' => $forum,
						'isAdmin' => $iAmAdmin,
						'isMember' => $iAmMember
					) )->getBuffer();
					if( $param2 === 'invalid' ) $output .= 'Please enter a post';
				}
				elseif( $action === 'new' ) {
					if( isset( $param ) && $param !== 'confirm' ) {
						$output = '';
						if( $param2 === 'invalid' ) $output = 'Please fill in all fields';
						$output .= BufferedView::instance('org/forms/thread', array(
							'action' => "/org/view/$name/thread/new/confirm",
							'hiddenInputs' => array( 'forum_id' => $param )
						) )->getBuffer();	
					} 
					elseif( $param === 'confirm' ) {
						try {
							if( !empty( $_POST['topic'] ) ) {
								$model->insertThread( $_POST['forum_id'], $_POST['topic'], $_SESSION['stud_no'], gmdate('Y-m-d H:i:s'), 0, 0, null, $_POST['post'] );
								header("Location: /org/view/$name/forum/view/{$_POST['forum_id']}");
							}
							else {
								header("Location: /org/view/$name/thread/new/{$_POST['forum_id']}/invalid");
							}
						} catch( Exception $e ) {
							$output = 'There has been an error.';
						}
					}
				}
				elseif( $action === 'edit' ) {
				}
				elseif( $action === 'delete' ) {
					$thread = $model->getThread($param);
					$output = 'Are you sure you wish to delete this thread?';
					$output .= BufferedView::instance('org/thread', array(
						'thread' => $thread,
					))->getBuffer();
					$output .= BufferedView::instance('public/forms/confirm', array(
						'action' => "/org/view/$name/thread/delete-confirm/$param",
						'hiddenInputs' => array()
					))->getBuffer();
				}
				elseif( $action === 'delete-confirm' ) {
					if( $_POST['confirm-yes'] ) {
						$forum = $model->lookupThreadForum($param);
						$model->deleteThread($param);
						header("Location: /org/view/$name/forum/view/$forum");
					}
					elseif( $_POST['confirm-no'] ) {
						$forum = $model->lookupThreadForum($param);
						header("Location: /org/view/$name/forum/view/$forum");
					}
					$output = 'Are you sure you wish to delete this thread?';
					$output .= BufferedView::instance('org/thread', array(
						'thread' => $thread,
					))->getBuffer();
					$output .= BufferedView::instance('public/forms/confirm', array(
						'action' => "/org/view/$name/forum/delete-confirm/$param",
						'hiddenInputs' => array()
					))->getBuffer();
				}
				$templateVars =  array(
					'title' =>  'Thread - FEELS ',
					'heading' => $org[0]['description'],
					'highlight' => 'orgforum',
					'currentOrg' => $name,
					'content' => $output
				);	
			}

			elseif( $section === 'post' ) {
				$this->session();
				if( !empty( $_POST['message'] ) ) {
					$model = new forum();
					$date = gmdate ( 'Y-m-d H:i:s' );
					$post = $model->insertPost($_POST['threadId'],$_SESSION['stud_no'], $date, $_POST['message'] ); 
					header("Location: /org/view/$name/thread/view/{$_POST['threadId'] }");
				}
				else {
					header("Location: /org/view/$name/thread/view/{$_POST['threadId']}/invalid");
				}
			}
			elseif( $section === 'edit-post' ) {
				$this->session();
				$templateVars =  array(
					'title' =>  'Post - FEELS ',
					'heading' => $org[0]['description'],
					'highlight' => 'orgforum',
					'currentOrg' => $name,
					'content' => BufferedView::instance('org/edit_post',array(
						"message" => $_POST['message'],
						"postId" => $_POST['postId'],
						"threadId" => $_POST['threadId'],
						'orgname' => $name
					) )->getBuffer()
				);		
			}
			elseif( $section === 'edit-post-confirm' ) {
				$this->session();
				$model = new forum();
				$post = $model->updatePost($_POST['message'],$_POST['postId'] ); 
				header("Location: /org/view/$name/thread/{$_POST['threadId'] }");
			}
			elseif( $section === 'delete-post' ) {
				$this->session();
				$model = new forum();
				$post = $model->getPost( $action );
				$post = $post[0];
				$templateVars =  array(
					'title' =>  'Post - FEELS ',
					'heading' => $org[0]['description'],
					'highlight' => 'orgforum',
					'currentOrg' => $name,
					'content' => 'Are you sure you wish to delete the following post?'
					. BufferedView::instance('org/post',array(
						"row" => $post,
						"postId" => $_POST['postId'],
						"threadId" => $_POST['threadId'],
						'orgname' => $name
					) )->getBuffer()
					. BufferedView::instance('public/forms/confirm',array(
						"action" => "/org/view/$name/delete-post-confirm",
						"message" => $_POST['message'],
						"threadId" => $_POST['threadId'],
						'hiddenInputs' => array(
							"postId" => $action,
							'referrer' => $_SERVER['HTTP_REFERER']
						),
						'orgname' => $name
					) )->getBuffer()
				);		
			}
			elseif( $section === 'delete-post-confirm' ) {
				$this->session();
				if( $_POST['confirm-yes'] ) {
					$model = new forum();
					$post = $model->deletePost( $_POST['postId']); 
					header("Location: " . $_POST['referrer'] );
				}
				elseif( $_POST['confirm-no'] ) {
					header("Location: " . $_POST['referrer'] );
				}
				//header("Location: /org/view/$name/thread/{$_POST['threadId'] }");
			}			
			elseif( $section === 'photos') {
				$this->session();
				$orgid = $org[0]['org_id'];
				if( $action === NULL || $action === 'oversize' || $action === 'notimage' ) {
					$oldpath = getcwd();
					$path = "./photos/$orgid/";
					if( file_exists($path) && is_dir($path) ) {
						chdir($path);
						$files = glob("*");
						$totalsize = 0;
						foreach( (array) $files as $file ) {
							$totalsize += filesize( $file );
						}
						$totalsize = sprintf("%.2f", $totalsize / 1048576);
						$output .= "<h2 class=\"heading\">Org graphics</h2>";
						if( $action === 'oversize' ) $output .= "<div style=\"font-weight: bold;\">file uploaded would go over the limit</div>";
						if( $action === 'notimage' ) $output .= "<div style=\"font-weight: bold;\">file uploaded is not an image</div>";
						$output .= "$totalsize MB of 3 MB";
						$output .= "<div>Images only</div>	";
						$output .= '<form enctype="multipart/form-data" method="post" action="/org/view/'.$name.'/photos/add"><input type="file" name="file" /><input type="submit" value="Upload" /></form>';
						$output .= '<ul style="margin-left: 20px;"	>';
						if( $files !== false ) foreach( (array)$files as $filename) {
							$output .=  "<li>$filename(<a href=\"/photos/$orgid/$filename\">View</a>)(<a href=\"/org/view/$name/photos/delete/$filename\">Delete</a>)</li>\n";
						}
						$output .= '</ul>';
						chdir($oldpath);
					}
					else {
						$output .= 'Directory is not available for upload.';
					}
					$templateVars = array(
						'heading' => $org[0]['description'],
						'content' => $output,
						'currentOrg' => $name
					);
				}
				elseif( $action === 'add' ) {
					$oldpath = getcwd();
					$path = "./photos/$orgid/";
					if( file_exists($path) && is_dir($path) ) {
						chdir($path);
						$files = glob("*");
						$totalsize = 0;
						foreach( (array) $files as $file ) {
							$totalsize += filesize( $file );
						}
						chdir($oldpath);
						if( $totalsize + $_FILES['file']['size'] > 3*1048576 ) {
							header("Location: /org/view/$name/photos/oversize");
						}
						else {
							$info = getimagesize( $_FILES['file']['tmp_name'] );
							if( $info === false ) header("Location: /org/view/$name/photos/notimage");
							elseif( move_uploaded_file( $_FILES['file']['tmp_name'], "./photos/$orgid/" . $_FILES['file']['name'] ) ) {
								header("Location: /org/view/$name/photos");
							}
						}
					}
					
				}
				elseif( $action === 'delete' ) {
					$output = "<h2 class=\"heading\">Delete</h2>";
					$oldpath = getcwd();
					$path = "./photos/$orgid/";
					if( file_exists($path) && is_dir($path) ) {
						chdir($path);
						if( file_exists( $param ) ) {
							$output .= "Are you sure you want to delete $param?";
						}	
						chdir($oldpath);
					}
					$templateVars = array(
						'heading' => $org[0]['description'],
						'content' => $output
						. BufferedView::instance('public/forms/confirm', array(
							'action' => "/org/view/$name/photos/delete-confirm/$param",
							'hiddenInputs' => array()
						))->getBuffer()
					);
				}
				elseif( $action === 'delete-confirm' ) {
					$oldpath = getcwd();
					$path = "./photos/$orgid/";
					if( file_exists($path) && is_dir($path) ) {
						chdir($path);
						if( file_exists($param) ) unlink( $param );
						chdir($oldpath);
						header("Location: /org/view/$name/photos");
					}
					else {
						echo 'file dne';
					}
				}
				$templateVars['highlight'] = 'orggraphics';
			}
			elseif( $section === 'memberlist' ) {
				$membersModel = new member();
				$members = $membersModel->getOrgMembersByOrgName( $name );
				$templateVars =  array(
					'title' =>  $org[0]['description'] .' - Members - FEELS ',
					'heading' => $org[0]['description'],
					'highlight' => 'orgmember',
					'currentOrg' => $name,
					'content' => BufferedView::instance('org/memberlist',
						array(
							'name' => $org['name'],
							'description' => $org['description'],
							'long_description' => $org['long_description'],
							'announcements' => $article,
							'members' => $members
						)
					)->getBuffer()
				);
			}
		}
		if( $templateVars['highlight'] === null ) $templateVars['highlight'] = '';
		if( $templateVars['currentOrg'] === null ) $templateVars['currentOrg'] = '';
		if( $iAmBanned ) $templateVars['content'] .= '<div style="margin-top: 20px;font-weight: bold">&gt;You have been banned! Some features are disabled from this course. Please look for your professor listed at the course information to fix your account.</div>';
		new View('template', 
			array_merge( 
				array(
					'globalnav' => new BufferedView('org/globalnav',
						array(
							'isMember' => $iAmMember,
							'inboxUnread' => $inboxUnread
						)
					),
					'usernav' => new BufferedView('org/usernav', 
						array(
							'highlight' => $templateVars['highlight'], 
							'currentOrg' => $templateVars['currentOrg'],
							'isMember' => $iAmMember,
							'orgAdmin' => $iAmAdmin
						)
					),
					'style' => $org[0]['css']
				),
				$templateVars
			)
		);		

	}
	
}
